package com.vainycos.lotterysearch.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vainycos.lotterysearch.mapper.ClassicQuotMapper;
import com.vainycos.lotterysearch.model.ClassicQuotDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @author: Vainycos
 * @description
 * @date: 2022/11/23 13:28
 */
@Service
public class ClassicQuotService extends ServiceImpl<ClassicQuotMapper, ClassicQuotDO> {

    @Autowired
    private ClassicQuotMapper classicQuotMapper;

    /**
     * 获取列表
     * @param type 语录类型 1-football
     * @return
     */
    public List<ClassicQuotDO> getListByType(int type){
        return classicQuotMapper.selectList(new LambdaQueryWrapper<ClassicQuotDO>().eq(ClassicQuotDO::getType, type));
    }

    /**
     * 随机获取一个
     * @param type 语录类型 1-football
     * @return
     */
    public ClassicQuotDO getOneByType(int type){
        List<ClassicQuotDO> classicQuotDOS = classicQuotMapper.selectList(new LambdaQueryWrapper<ClassicQuotDO>().eq(ClassicQuotDO::getType, type));
        Collections.shuffle(classicQuotDOS);
        return classicQuotDOS.get(0);
    }
}
